<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="创建人" prop="creator.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.creator.id" @getValue='(value) => {inputForm.creator.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="创建人单位" prop="createUnit.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="createUnit"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.createUnit.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.createUnit.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标编号" prop="tenderNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tenderNumber" placeholder="请填写投标编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标主体" prop="tenderSubject"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tenderSubject" placeholder="请填写投标主体"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标项目部" prop="tenderProjectDepartment.id"
                :rules="[
                  {required: true, message:'投标项目部不能为空', trigger:'blur'}
                 ]">
          <SelectTree
                      ref="tenderProjectDepartment"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.tenderProjectDepartment.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.tenderProjectDepartment.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标部门" prop="tenderDepartment.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="tenderDepartment"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.tenderDepartment.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.tenderDepartment.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标起始日期" prop="tenderDeadline"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tenderDeadline" placeholder="请填写投标起始日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标有效期" prop="tendervaltenderValiditydity"
                :rules="[
                 ]">
              <el-input v-model="inputForm.tendervaltenderValiditydity" placeholder="请填写投标有效期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标区域" prop="tenderArea"
                :rules="[
                 ]">
                <el-select v-model="inputForm.tenderArea" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('tenderarea')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="招标名称" prop="bidName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bidName" placeholder="请填写招标名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="招标编号" prop="bidNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bidNumber" placeholder="请填写招标编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="招标单位" prop="bidUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bidUnit" placeholder="请填写招标单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="客户类别" prop="customerCategory"
                :rules="[
                 ]">
                <el-select v-model="inputForm.customerCategory" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('customer_category')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="招标代理机构" prop="bidAgency"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bidAgency" placeholder="请填写招标代理机构"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="代理机构联系人" prop="agencyContact"
                :rules="[
                 ]">
              <el-input v-model="inputForm.agencyContact" placeholder="请填写代理机构联系人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="代理机构联系方式" prop="agencyContactInformation"
                :rules="[
                 ]">
              <el-input v-model="inputForm.agencyContactInformation" placeholder="请填写代理机构联系方式"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="分管高管" prop="chargeExcutive"
                :rules="[
                 ]">
              <el-input v-model="inputForm.chargeExcutive" placeholder="请填写分管高管"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标性质" prop="tenderNature"
                :rules="[
                 ]">
                <el-select v-model="inputForm.tenderNature" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('tender_nature')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目类型" prop="projectType"
                :rules="[
                 ]">
                <el-select v-model="inputForm.projectType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('project_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="专业类别" prop="specialityClassification"
                :rules="[
                 ]">
                <el-select v-model="inputForm.specialityClassification" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('speciality_classification')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目规模" prop="projectScale"
                :rules="[
                 ]">
                <el-select v-model="inputForm.projectScale" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('project_scale')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="市场来源" prop="marketSources"
                :rules="[
                 ]">
                <el-select v-model="inputForm.marketSources" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('marketsources')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="购买标书日期" prop="dateOfTender"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.dateOfTender"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预估中标金额" prop="bidPrice"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bidPrice" placeholder="请填写预估中标金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="标段状态" prop="bidStatus"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bidStatus" placeholder="请填写标段状态"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="上传投标报价" prop="uploadBiddingQuotation"
                :rules="[
                 ]">
              <el-input v-model="inputForm.uploadBiddingQuotation" placeholder="请填写上传投标报价"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          creator: {
            id: ''
          },
          createUnit: {
            id: ''
          },
          tenderNumber: '',
          tenderSubject: '',
          tenderProjectDepartment: {
            id: ''
          },
          tenderDepartment: {
            id: ''
          },
          tenderDeadline: '',
          tendervaltenderValiditydity: '',
          tenderArea: '',
          bidName: '',
          bidNumber: '',
          bidUnit: '',
          customerCategory: '',
          bidAgency: '',
          agencyContact: '',
          agencyContactInformation: '',
          chargeExcutive: '',
          tenderNature: '',
          projectType: '',
          specialityClassification: '',
          projectScale: '',
          marketSources: '',
          dateOfTender: '',
          bidPrice: '',
          bidStatus: '',
          uploadBiddingQuotation: ''
        }
      }
    },
    components: {
      UserSelect,
      SelectTree
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建投标项目登记表`
        } else if (method === 'edit') {
          this.title = '修改投标项目登记表'
        } else if (method === 'view') {
          this.title = '查看投标项目登记表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/biddingprojectregistration/biddingProjectRegistration/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.biddingProjectRegistration)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/biddingprojectregistration/biddingProjectRegistration/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>